package com.mmsj;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

public class LoginActivity extends AppCompatActivity {

    EditText username;
    EditText password;
    Button loginButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_login);

        // 获取控件
        username = findViewById(R.id.et_user);
        password = findViewById(R.id.et_password);
        loginButton = findViewById(R.id.btn_login);

        // 给登录按钮添加点击事件
        loginButton.setOnClickListener(v -> {
            String user = username.getText().toString();
            String pass = password.getText().toString();
            if (user.isEmpty() || pass.isEmpty()){
                username.setError("用户名或密码不能为空");
            }
            else {
                if(user.equals("admin") && pass.equals("123")){
                    // 登录成功
                    // 跳转到主界面
                    startActivity(new Intent(LoginActivity.this, HomeActivity.class));
                }
                else {
                    username.setError("用户名或密码错误");
                }
            }
        });
    }
}